function index = fs_mpc(X,...
                 La,Wbase,vdc,Ts)
salfa = [2/3;1/3;-1/3;-2/3;-1/3;1/3;0;0];
sbeta = [0;sqrt(3)/3;sqrt(3)/3;0;-sqrt(3)/3;-sqrt(3)/3;0;0];
sa = [1,1,0,0,0,1,0,1];
sb = [0,1,1,1,0,0,0,1];
sc = [0,0,0,1,1,1,0,1];
iaref = X(1);
ibref = X(2);
iia_n1 = X(3);
iib_n1 = X(4);
vca_n1 = X(5);
vcb_n1 = X(6);

% embedded_integer = round(7*X(7));
% 
% % Extract c (least significant bit)
% cn1 = bitand(embedded_integer, 1);
% % Extract b by shifting right one bit and getting the least significant bit
% bn1 = bitand(bitshift(embedded_integer, -1), 1);
% % Extract a by shifting right two bits and getting the least significant bit
% an1 = bitand(bitshift(embedded_integer, -2), 1);
% 
valfa = vdc*salfa;
vbeta = vdc*sbeta;

%% current reference at step k

iref = iaref + 1i*ibref;



%% no need to compensation digital output delay
% va_n1 = va_n1 + 1i*vb_n1;

ii_n1 = iia_n1 + 1i*iib_n1;
vc_n1 = vca_n1 + 1i*vcb_n1;

ii = ii_n1;
vc = vc_n1;

%%
Jmin = 0;
index = 1;
for i=1:7
    a = sa(i);
    b = sb(i);
    c = sc(i);
    va = valfa(i) + 1i*vbeta(i);
    ii_1 = ii + Ts*(va-vc)/La*Wbase;
%     vc_1 = vc + Ts*(ii-iout_n1)/Cf*Wbase;
    J1 = (abs(iref-ii_1)*10)^2*0.25;
    % J2 = (a-an1)^2+(b-bn1)^2+(c-cn1)^2;
%     J2 = (abs(iref)-abs(ii_1))^2*0.25;
%     J3 = (abs(vc_1)-1)^2*0.25;
    J = J1;
    if i==1
        Jmin = J;
        index = 1;
    elseif J<=Jmin
        Jmin = J;
        index = i;
    end
end

% va_alfa = valfa(index);
% va_beta = vbeta(index);
% sa_index = sa(index);
% sb_index = sb(index);
% sc_index = sc(index);
% s = [sa_index;1-sa_index;sb_index;1-sb_index;sc_index;1-sc_index];
